<template>
  <div class="app-container">
    <el-card class="box-card" style="width: 35%; margin: 10% auto">
      <div slot="header" class="clearfix">
        <span>客户购气设置</span>
      </div>
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
        <el-form-item label="民用最大购气量" prop="civilMax">
          <el-input-number v-model="form.civilMax" controls-position="right" :min="1" />
        </el-form-item>
        <el-form-item label="工业最大购气量" prop="industrialMax">
          <el-input-number v-model="form.industrialMax" controls-position="right" :min="1" />
        </el-form-item>
        <el-button type="primary" style="margin: 30px 40%" @click="submitForm">保 存</el-button>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import {
  listPurchasegas,
  addPurchasegas,
  updatePurchasegas,
} from "@/api/systemSetup/gasPurchaseSettings";
export default {
  name: "gasPurchaseSettings",
  dicts: ["sys_normal_disable"],
  data() {
    return {
      // 表单参数
      form: {
        id: undefined,
        civilMax: undefined,
        industrialMax: undefined,
      },
      // 表单校验
      rules: {
        civilMax: [
          {
            required: true,
            message: "民用最大购气量不能为空",
            trigger: "blur",
          },
        ],
        industrialMax: [
          {
            required: true,
            message: "工业最大购气量不能为空",
            trigger: "blur",
          },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询岗位列表 */
    getList() {
      this.loading = true;
      listPurchasegas({}).then((response) => {
        this.form = response.rows[0];
        this.loading = false;
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != undefined) {
            updatePurchasegas(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPurchasegas(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
  },
};
</script>
